package com.toe.user.webapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.toe.common.exception.ToeServiceException;
import com.toe.common.restful.JsonPage;
import com.toe.common.restful.StateEnum;
import com.toe.pojo.dto.user.UserReportRemarkDTO;
import com.toe.pojo.entity.user.UserReportRemark;
import com.toe.pojo.vo.user.UserReportArticleVO;
import com.toe.pojo.vo.user.UserReportRemarkVO;
import com.toe.user.webapi.mapper.UserReportRemarkMapper;
import com.toe.user.service.UserReportRemarkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@DubboService
@Service
public class UserReportRemarkServiceImpl extends ServiceImpl<UserReportRemarkMapper, UserReportRemark> implements UserReportRemarkService {
    @Autowired
    private UserReportRemarkMapper userReportRemarkMapper;

    @Override
    public void addReportRemark(UserReportRemarkDTO userReportRemarkDTO) {
        int rows = userReportRemarkMapper.insertReportRemark(userReportRemarkDTO);
        if(rows != 1) {
            throw new ToeServiceException(StateEnum.ERR_SERVER_BUSY,"服务器繁忙，插入评论举报表失败");
        }
    }

    @Override
    public JsonPage<UserReportRemarkVO> pageReportRemark(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<UserReportRemarkVO> pageRemarks = userReportRemarkMapper.selectReportRemark();
        return JsonPage.restPage(new PageInfo<>(pageRemarks));
    }

    @Override
    public void forbidRemark(Long id) {
        int rows = userReportRemarkMapper.forbidIsHandled(id);
        if(rows != 1) {
            throw new ToeServiceException(StateEnum.ERR_SERVER_BUSY,"服务器繁忙");
        }
    }

    @Override
    public void passRemark(Long id) {
        int rows = userReportRemarkMapper.passIsHandled(id);
        // 等待国能：根据id删除评论的接口
        if(rows != 1) {
            throw new ToeServiceException(StateEnum.ERR_SERVER_BUSY,"服务器繁忙");
        }
    }
}
